package com.ysy.controller;

import com.ysy.dto.IdRequestDTO;
import com.ysy.dto.IdsRequestDTO;
import com.ysy.dto.UserDTO;
import com.ysy.dto.UserReqDTO;
import com.ysy.persimmons.common.response.Response;
import com.ysy.service.UserService;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author yangSy
 * @since 2025-04-21
 */
@RestController
public class UserController {

    private static final Logger log = LoggerFactory.getLogger(UserController.class);

    @Resource
    private UserService userService;

    /**
     * 手机号查询用户信息
     */
    @PostMapping(value = "/user/findByPhone")
    Response<UserDTO> findByPhone(@RequestBody UserReqDTO userReqDTO){
        return userService.findByPhone(userReqDTO);
    };

    /**
     * 用户注册
     */
    @PostMapping("/user/register")
    Response<Long> registerUserByPhone(@RequestBody UserReqDTO userReqDTO){
        return userService.registerUserByPhone(userReqDTO);
    };


    /**
     * 更新密码
     */
    @PostMapping( "/user/password/update")
    Response<?> updatePassword(@RequestBody UserReqDTO userReqDTO){
        return userService.updatePassword(userReqDTO);
    };

    /**
     * 根据用户 ID 查询用户信息
     */
    @PostMapping("/user/findById")
    Response<UserDTO> findById( @RequestBody IdRequestDTO idRequestDTO){
        return userService.findById(idRequestDTO);
    };

    /**
     * 批量查询用户信息
     */
    @PostMapping("/user/findByIds")
    Response<List<UserDTO>> findByIds(@RequestBody IdsRequestDTO idsRequestDTO){
        return userService.findByIds(idsRequestDTO);
    };

}
